package com.ruoyi.business.service.impl;



import com.ruoyi.business.service.ClassPermissionsService;

import com.ruoyi.business.service.IWsdRoleClassService;
import com.ruoyi.business.service.IWsdStudentsService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.WsdRoleClass;
import com.ruoyi.common.core.domain.entity.WsdStudents;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;

/**
 * @Author itmei
 * @Date 2024/5/18 17:05
 * @description:
 * @Title: FuiouNotifyServiceImpl
 * @Package com.ruoyi.business.service
 */
@Slf4j
@Service
public class ClassPermissionsServiceImpl implements ClassPermissionsService {
    @Autowired
    private IWsdStudentsService wsdStudentsService;
    @Autowired
    private IWsdRoleClassService wsdRoleClassService;
    @Override
    public String classIds() {
        String classIds = "";
        //获取当前登陆用户
        SysUser user = getLoginUser().getUser();
        //用户类型
        if ("00".equals( user.getUserType() )){//老师
            if (user.getRoles().size()>0){
                ArrayList<Long> classIdss = new ArrayList<>();
                for (int i = 0; i < user.getRoles().size(); i++){
                    WsdRoleClass wsdRoleClass = new WsdRoleClass();
                    wsdRoleClass.setRoleId( user.getRoles().get( i ).getRoleId() );
                    List<WsdRoleClass> wsdRoleClassList = wsdRoleClassService.selectWsdRoleClassList(wsdRoleClass);
                    if (wsdRoleClassList.size()>0){
                        for (WsdRoleClass wsdRoleClass1 : wsdRoleClassList){
                            classIdss.add( wsdRoleClass1.getClassId() );
                        }
                    }
                }
                classIdss = classIdss.stream()
                        .distinct()
                        .collect( Collectors.toCollection(ArrayList::new));
                StringBuilder classIdsBuilder = new StringBuilder();
                for (Long classId : classIdss) {
                    classIdsBuilder.append(classId).append(",");
                }
                if (classIdsBuilder.length() > 0) {
                    classIds = classIdsBuilder.substring(0, classIdsBuilder.length() - 1);
                } else {
                    classIds = "";
                }
            }
        } else if ("11".equals( user.getUserType() )) {//小程序用户/家长
            WsdStudents wsdStudents = wsdStudentsService.selectWsdStudentsById(user.getStudentId());
            classIds = wsdStudents.getClassId().toString();
        } else if ("22".equals( user.getUserType() )) {//饭堂人员

        }else if ("33".equals( user.getUserType() )) {//老师

        }
        return classIds;
    }
}
